import request from '@/api/request.js'

const url = '/user'
const queryBySearchUrl = url + '/queryBySearch'
const setRolesUrl = url + '/setRoles'
const listRoleByUserIdUrl = url + '/listRoleByUserId'
const alterPasswordUrl = url + '/alterPassword'
const getCurrentUserRolesUrl = url + '/getCurrentUserRoles'
const getCurrentInterfaceUrlsUrl = url + '/getCurrentInterfaceUrls'
const getCurrentRoutersTreeUrl = url + '/getCurrentRoutersTree'
const getCurrentButtonsUrl = url + '/getCurrentButtons'
const getDetailUrl = url + '/getDetail'
const getMenuTreeUrl = url + '/getMenuTree'
const listMenuTreeUrl = url + '/listMenuTree'
const logoutUrl = url + '/logout'
const listOrgByMenuIdUrl = url + '/listOrgByMenuId'
const accessTokenUrl = url + '/accessToken'
const setHeadSculptureUrl = url + '/setHeadSculpture'
const listBySearchUrl = url + '/listBySearch'
const listByOrgIdsUrl = url + '/listByOrgIds'

export default {
  url,
  /**
   * 获取当前用户的角色列表
   */
  getCurrentUserRoles() {
    return request.httpGet(getCurrentUserRolesUrl)
  },
  /**
   * 获取当前用户权限
   */
  getCurrentInterfaceUrls() {
    return request.httpGet(getCurrentInterfaceUrlsUrl)
  },
  /**
   * 获取当前用户路由树
   * @return {Promise<AxiosResponse<any>>}
   */
  getCurrentRoutersTree() {
    return request.httpGet(getCurrentRoutersTreeUrl)
  },
  getCurrentButtonsUrl,
  /**
   * 获取用户可以访问的所有按钮集合
   * @returns
   */
  getCurrentButtons() {
    return request.httpGet(getCurrentButtonsUrl, {});
  },
  setRoles(params) {
    return request.httpPost(setRolesUrl, params)
  },
  listRoleByUserId(params) {
    return request.httpGet(listRoleByUserIdUrl, params)
  },
  alterPassword(params) {
    return request.httpPut(alterPasswordUrl, params)
  },
  /**
   * 获取当前用户信息
   * @return {Promise<AxiosResponse<any>>}
   */
  getDetail() {
    return request.httpGet(getDetailUrl, {})
  },
  /**
   * 根据group获取当前用户可访问的菜单数据
   * @param params
   * @returns {*}
   */
  getMenuTree(params) {
    return request.httpGet(getMenuTreeUrl, params)
  },
  /**
   * 获取当前用户可以访问的菜单结构
   *
   * @returns [{group,menuTrees}]
   */
  listMenuTree() {
    return request.httpGet(listMenuTreeUrl, {})
  },
  /**
   * 退出登陆功能,不需要传任何参数
   * @return {Promise<AxiosResponse<any>>}
   */
  logout() {
    return request.httpPut(logoutUrl)
  },
  /**
   * 根据token登陆系统
   * @param {string} params.code - 当前用户的token
   * @return {Promise<AxiosResponse<any>>}
   */
  accessToken(params) {
    return request.httpGet(accessTokenUrl, params, {
      headers: {
        isToken: false
      }
    })
  },
  /**
   * 设置当前用户的头像
   * @param {String} params.headSculptureId - 头像文件ID
   * @return {Promise<AxiosResponse<any>>}
   */
  setHeadSculpture(params) {
    return request.httpPut(setHeadSculptureUrl, params)
  },
  /**
   * 根据查询条件分页获取用户信息
   */
  queryBySearch(params) {
    return request.httpGet(queryBySearchUrl, params)
  },
  listBySearch(params) {
    return request.httpPost(listBySearchUrl, params)
  },
  listByOrgIds(params) {
    return request.httpGet(listByOrgIdsUrl, params)
  },
}
